package com.ylkj.common.util;

/**
 * MAP工具类.
 * 
 * @author 呼云飞
 */
public class MapUtil {
    /**
     * 用户获取map data
     *
     * @param obj
     * @return
     */
    public static String getString(Object obj) {
        return (obj == null) ? "" : String.valueOf(obj);
    }

    /**
     * 用于获取map data,出错返回0
     *
     * @param obj
     * @return
     */
    public static Integer getInteger(Object obj) {
        try {
            return (obj == null || obj.equals("")) ? 0 : new Integer(obj.toString());
        } catch (NumberFormatException ex) {
            return 0;
        }
    }

    /**
     * 用于获取map data 出错返回0
     *
     * @param obj
     * @return
     */
    public static Double getDouble(Object obj) {
        try {
            return (obj == null || obj.equals("")) ? 0 : new Double(obj.toString());
        } catch (NumberFormatException ex) {
            return 0d;
        }
    }

    /**
     * 用于获取map data 出错返回0
     *
     * @param obj
     * @return
     */
    public static Long getLong(Object obj) {
        try {
            return (obj == null || obj.equals("")) ? 0 : new Long(obj.toString());
        } catch (NumberFormatException ex) {
            return 0l;
        }
    }
}
